var historyObj = {
    reqBodyobj: "",
    nPageIndex:"0",
    flage:0,
    init: function () {
        this.gethistortData();
        this.loadMore()
    },
    loadMore: function () {
        var me = this;
        $(window).scroll(function () {
            if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
                if (me.flage == 0) {

                    me.nPageIndex  = (Number(me.nPageIndex)+1).toString();
                    me.gethistortData(2);
                } else {
                    publicObj.myalert("没有更多啦~~")
                }

            }
        });
    },
    gethistortData: function (callbackparameter) {
        var contentType = 'application/x-www-form-urlencoded';
        var reqType = "POST";
        var isAsync = true;
        var dataType = "json";
        var reqUrl = ruquireObj.urlPrefix + 'ApproveService/getdeptmallapproveorderslist';
        var callbackparameter = callbackparameter;
        var reqBody = {
            nPageIndex: this.nPageIndex
        };
        this.reqBodyobj = reqBody;
        publicObj.showLoad();
        publicObj.myAjax(this, this.gethistortDataSug, reqUrl, this.reqBodyobj, reqType, isAsync, dataType,contentType,callbackparameter);

    },
    gethistortDataSug: function (res, obj,callbackparameter) {
        publicObj.hideLoad();
        var me = obj;
        if (res.return.nCode == 0) {
            var resObj = res.response;
            var dataList = resObj.cdoDataList;
            console.log(dataList);
            if (dataList.length == 0) {
                me.flage = 1;
            }
            var str = '';
            for (var i = 0; i < dataList.length; i++) {
                //商品信息列表
                var goodsStr = '';
                console.log(dataList[i].poshead.posSaledtl);
                for (var j = 0; j < dataList[i].poshead.posSaledtl.length; j++) {

                    goodsStr += '<div class="center kind1"><div class="goodsname"><div class="goodsnametxt">' + dataList[i].poshead.posSaledtl[j].sGoodsName + '</div><div class="barcode">' + dataList[i].poshead.posSaledtl[j].sBarcode + '</div></div><div class="pric">￥' + Number(Number(dataList[i].poshead.posSaledtl[j].nPluAmount) - Number(dataList[i].poshead.posSaledtl[j].nPluDis)).toFixed(2) + '</div><div class="num">' + dataList[i].poshead.posSaledtl[j].nQty + '</div></div>'
                }
                //商品图片列表
                var imgStr = "";
                if (dataList[i].poshead.posHeadExt) {
                    var imgArry = dataList[i].poshead.posHeadExt.sImgUrl.split(",");
                    for (var k = 0; k < imgArry.length; k++) {
                        imgStr += ' <div class="imgbox"><img src="' + imgArry[k] + '"></div>';
                    }
                }
                //审批状态
                var approvestate;
                if(dataList[i].nApproveStatus == 0){
                    approvestate = '审批中';
                }else  if(dataList[i].nApproveStatus == 1){
                    approvestate = '已同意';
                }else  if(dataList[i].nApproveStatus == 99){
                    approvestate = '已撤销申请';
                }else  if(dataList[i].nApproveStatus == 98){
                    approvestate = '退款失败';
                }else {
                    approvestate = '已拒绝';
                }
                str += '<div class="datalistbox"><div class="top">收款时间' + dataList[i].poshead.dCreateTime + '<text class="approvalstatus">'+approvestate+'</text></div><div class="centerbox"><div class="normalgoods">' + goodsStr + '</div><div class="center kind2">' + imgStr + '</div><div class="totalbox totalbox2"><div class="total"> 共' + dataList[i].poshead.nTotalQty + '件商品，实收<text>￥' + dataList[i].poshead.nRealPayVal + '</text></div></div></div><div class="bottom"><div orderid = "' + dataList[i].poshead.sDealCount + '" class="seeorder">查看详情</div></div></div>';
            }
            if (callbackparameter == 2) {
                $('.datalistwall').append(str);
            } else {
                if(dataList.length == 0){
                    $(".datalistwall").hide();
                    $(".no").show();
                }else {
                    $(".datalistwall").show();
                    $(".no").hide();
                    $('.datalistwall').html(str);
                }
            }
            me.toOrder();
        } else {

        }
    },
    //前往订单详情
    toOrder: function () {
        $(".seeorder").each(function () {
            $(this).unbind('click').bind('click', function (e) {
                var orderid = $(this).attr("orderid")
                location.href = "./transaction.html?oriderid=" + orderid + '&form=operadata';

            })
        });
    }

};
historyObj.init();